﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.XCMG.Util;

namespace PMS.XCMG.Entity
{
    /// <summary>
    /// 下发到PLC明细
    /// </summary>
    public partial class SpecAssignDetail : BusEntity
    {
        /// <summary>
        /// 下发ID
        /// </summary>
        public string AssignId { get; set; }
        /// <summary>
        /// PLC IP地址
        /// </summary>
        public string PlcIp { get; set; }
        /// <summary>
        /// 逻辑地址
        /// </summary>
        public string LogAddr { get; set; }
    }

    public partial class SpecAssignDetail : BusEntity
    {
        /// <summary>
        /// 
        /// </summary>
        public SpecAssign Assign { get; set; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class SpecAssignDetailTypeConfig : BusEntityTypeConfig<SpecAssignDetail>, IEntityTypeConfiguration<SpecAssignDetail>
    {
        public override void Configure(EntityTypeBuilder<SpecAssignDetail> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.Assign).WithMany(m => m.AssignDetail).HasForeignKey(p => p.AssignId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.AssignId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.PlcIp).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.LogAddr).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            #endregion

            #region 备注
            builder.HasComment("下发到PLC明细");
            builder.Property(p => p.AssignId).HasComment("下发ID");
            builder.Property(p => p.PlcIp).HasComment("PLC IP地址");
            builder.Property(p => p.LogAddr).HasComment("逻辑地址");
            #endregion

            #region 种子数据
            #endregion
        }
    }
}
